<section class="content" style="padding: 10px">
    <div class="row">
        <div class="col-12">
            <div class="card card-default">
                <div class="card-header">
                    <h3 class="card-title">搜索</h3>
                </div>

                <div class="card-body">
                    <form role="form" data-form="1" data-search-table-id="1" data-title="自定义标题" >
                        <div class="form-inline"  >
                            {if $adminInfo['role']==1}
                            <div class="form-group">
                                <label  >医院：</label>
                                <select name="hospital_id" id="hospital" class="selectpicker">
                                    {:options,$hospital_select}
                                </select>
                            </div>
                            <div class="form-group" >
                                <label  >房间：</label>
                                <select name="room_id" id="room" class="selectpicker" >
                                </select>
                            </div>
                            {else}
                            <div class="form-group">
                                <label  >房间：</label>
                                <select name="room_id" class="selectpicker">
                                    {:options,$room_select}
                                </select>
                            </div>
                            {/if}
                            <div class="form-group">
                                <label>床位位名称/编号：</label>
                                <input type="text" class="form-control" name="name" placeholder="">
                            </div>
                            <div class="form-group">
                                <label  >空床：</label>
                                <select name="is_empty"  class="selectpicker">
                                    {:options,$is_empty}
                                </select>
                            </div>


                            <div class="form-group" style="margin-left: 10px">
                                <button type="submit" class="btn btn-primary">提交</button>
                                <button type="reset" class="btn btn-default">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>




<div class="content">
    <div class="card-body table-responsive" style="padding-top: 0px">
        <a class="btn   btn-outline-primary btn-table-tool btn-dialog" href="{url bed add_edit}&room_id={$room_id}" data-area="40%,40%" title="新增类别">新增</a>
    </div>
    <div class="card-body table-responsive" style="padding-top: 0px">
        <table data-table="1" data-url="{url bed ajax_data }&room_id={$room_id}" id="table1" class="table table-hover">
            <thead>
            <tr>

                <th data-field="id" data-formatter="epiiFormatter">ID</th>

                <th data-field="name" data-formatter="epiiFormatter">床位名称/编号</th>
                <th data-field="hospital_name" data-formatter="epiiFormatter">所属医院</th>
                <th data-field="room_name" data-formatter="epiiFormatter">所属房间</th>
                <th data-field="status" data-formatter="epiiFormatter.switch" data-on-change-url="{url bed status }&id={id}">状态</th>
                <th data-field="is_empty" data-formatter="epiiFormatter.switch" data-on-change-url="{url bed setEmpty }&id={id}">是否空床</th>

                <th data-field="addtime" data-formatter="epiiFormatter">时间</th>

                <th data-formatter="epiiFormatter.btns"
                    data-btns="edit"
                    data-edit-url="{url bed add_edit}&id={id}&room_id={$room_id}"
                    data-edit-title="编辑：{name}"
                    data-del-url="{url bed del }&id={id}"
                    data-del-title="删除：{name}"
                    data-area="40%,40%"
                >操作
                </th>
            </tr>
            </thead>
        </table>
    </div>

</div>
<script>

    window.onEpiiInit(function() {
        // 省份下拉框改变时，更新城市下拉框
        $("#hospital").change(function(){
            var hospital = $(this).val();
            if (hospital == "") {
                $("#room").html("<option value=''>请选择房间</option>");
            }
            $.ajax({
                url: '?app=bed@getRoomByHospital&hospital_id='+hospital,
                type: 'get',
                dataType:'json',
                success: function(data) {
                    for (let i=0;i<data.length;i++){
                        var option = "<option value='"+data[i].id+"'>"+data[i].name+"</option>"; // 创建一个新的<option>元素tion>元素的文本内容
                        $('#room').append(option); // 将<option>元素添加到id为citySelect的<
                    }
                    $('#room').selectpicker('refresh');
                }
            });

        });
        // generateCityOptions();
    });

</script>
